package com.it.blog.service.impl;

import cn.hutool.core.date.DateUtil;
import com.it.blog.dao.WebsiteConfigDao;
import com.it.blog.entity.WebsiteConfig;
import com.it.blog.service.WebsiteConfigService;
import com.it.blog.tools.CompTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * @Author: 羡羡
 * @Date: 2022/01/29/10:25
 */
@Service
public class WebsiteConfigServiceImpl implements WebsiteConfigService {
    @Autowired
    WebsiteConfigDao website;


    /**
     * 查询网站信息
     * @return
     */
    @Override
    public WebsiteConfig webconfigall() {
        WebsiteConfig web=website.webconfigall();
        return web;
    }

    /**
     * 计算运行时间
     * @return
     */
    @Override
    public String GetComTime(){
        //查询所有信息
        WebsiteConfig web=website.webconfigall();
        //截取数据库开始时间
        String[] time=web.getWebsitetime().split("-");
        //年
        int year= Integer.parseInt(time[0]);
        //月
        int month= Integer.parseInt(time[1]);
        //日
        int day= Integer.parseInt(time[2]);
        /*System.out.println(year+" "+month+" "+day);*/

        //截取当前时间
        String[] today= DateUtil.today().split("-");
        int nowyear= Integer.parseInt(today[0]);
        int nowmoth= Integer.parseInt(today[1]);
        int nowday= Integer.parseInt(today[2]);
        /*System.out.println("now:"+nowyear+" "+nowmoth+" "+nowday);*/
        //设置开始时间
        LocalDate start= LocalDate.of(year,month,day);
        //设置结束时间
        LocalDate end=LocalDate.of(nowyear,nowmoth,nowday);
        //计算结果
        String res=CompTime.comtime(start,end);
        return res;
    }
}
